package com.chinasoft;

import javax.swing.*;

public class FirstView {
    public static void main(String[] args) {
        // 创建主窗口对象
        JFrame jFrame = new JFrame("骑士夺宝");
        // 设置窗框的位置和大小，以及可见性
        jFrame.setBounds(100, 100, 815, 655);
        jFrame.setVisible(true);
        // 设置窗口标题
        jFrame.setTitle("骑士夺宝");
        // 设置窗口图标
        jFrame.setIconImage(new ImageIcon("src/main/resources/image/person01.png").getImage());
        // 设置窗口关闭操作，点击关闭按钮时退出程序
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // 创建面板并设置布局为null，以便手动设置组件位置
        JLayeredPane jPanel = new JLayeredPane();
        jPanel.setLayout(null);
        // 添加面板到内容面板中
        jFrame.add(jPanel);

        // 添加背景图片
        JLabel bg = new JLabel(new ImageIcon("src/main/resources/image/guanka.png"));
        bg.setBounds(5, 5, 790, 600);
        jPanel.add(bg, JLayeredPane.DEFAULT_LAYER);

        // 游戏启动按钮
        JLabel start = new JLabel();
        start.setIcon(new ImageIcon("src/main/resources/image/start02.png"));
        start.setBounds(304, 258, 186, 42);
        // 实例化
        ButtonMenu buttonMenu = new ButtonMenu();
        ButtonMenu.StartButtonAdapter startButtonAdapter = buttonMenu.new StartButtonAdapter(jFrame);
        // 添加鼠标监听,将jFrame传进去，以打开新窗口并关闭旧窗口
        start.addMouseListener(startButtonAdapter);
        jPanel.add(start, JLayeredPane.MODAL_LAYER);

        // 游戏退出按钮
        JLabel exitGame = new JLabel();
        exitGame.setIcon(new ImageIcon("src/main/resources/image/exit-bt01.png"));
        exitGame.setBounds(304, 358, 186, 42);
        // 添加鼠标监听以处理退出游戏事件
        ButtonMenu.ExitButtonAdapter exitButtonAdapter = buttonMenu.new ExitButtonAdapter();
        exitGame.addMouseListener(exitButtonAdapter);
        jPanel.add(exitGame, JLayeredPane.MODAL_LAYER);

        // 主界面图标
        JLabel lblMainIcon = new JLabel("New label");
        lblMainIcon.setIcon(new ImageIcon("src/main/resources/image/2.png"));
        lblMainIcon.setBounds(256, 61, 299, 132);
        jPanel.add(lblMainIcon, JLayeredPane.MODAL_LAYER);
    }

}
